package summary;

/**
 * @Author: 海琳琦
 * @Date: 2022/7/22 21:00
 * https://leetcode.cn/problems/corporate-flight-bookings/
 */
public class Title1109 {

    public int[] corpFlightBookings(int[][] bookings, int n) {
        //定义result为每站座位数量的变化
        int[] result = new int[n];
        for (int[] book : bookings) {
            int start = book[0] - 1;
            //无人预定座位
            int end = book[1];
            int seats = book[2];
            result[start] += seats;
            if (end < n) {
                result[end] -= seats;
            }
        }
        for (int i = 1; i < n; i++) {
            result[i] += result[i - 1];
        }
        return result;
    }


    public int[] corpFlightBookings2(int[][] bookings, int n) {
        int[] result = new int[n];
        for (int[] booking : bookings) {
            int start = booking[0] - 1;
            int end = booking[1] - 1;
            int seat = booking[2];
            for (int i = start; i <= end; i++) {
                result[i] += seat;
            }
        }
        return result;
    }

    public static void main(String[] args) {
        int c = 'a';

    }
}

